home *** CD-ROM | disk | FTP | other *** search
- -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C)
- -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
- --
- expanded class CHARACTER
- --
- -- Note : corresponding C type is "char"
- --
- inherit
- CHARACTER_REF
- redefine
- infix "<", infix "<=", infix ">", infix ">=", compare,
- code, to_lower, to_upper, print_on
- end;
-
- feature {ANY}
-
- code: INTEGER is
- -- ASCII code of Current.
- external "CSE"
- end;
-
- infix "<"(other: CHARACTER): BOOLEAN is
- -- Comparison using `code'.
- external "CSE"
- end;
-
- infix "<="(other: CHARACTER): BOOLEAN is
- -- Comparison using `code'.
- external "CSE"
- end;
-
- infix ">"(other: CHARACTER): BOOLEAN is
- -- Comparison using `code'.
- external "CSE"
- end;
-
- infix ">="(other: CHARACTER): BOOLEAN is
- -- Comparison using `code'.
- external "CSE"
- end;
-
- compare (other: CHARACTER): INTEGER is
- -- Compare Current with `other'.
- -- '<' <==> Result < 0
- -- '>' <==> Result > 0
- -- Otherwise Result = 0
- do
- Result := code - other.code
- end;
-
- value: INTEGER is
- -- Gives the value of a digit.
- require
- is_digit
- do
- Result := code - 48;
- ensure
- 0 <= Result and Result <= 9;
- definition: Result = code - 48;
- end; -- value
-
- same_as(other : CHARACTER): BOOLEAN is
- -- No difference upper/lower.
- do
- Result := to_lower = other.to_lower;
- ensure
- Result implies to_lower = other or to_upper = other;
- end ;
-
- to_upper: CHARACTER is
- -- Conversion to the corresponding upper case.
- do
- if code < 97 then
- Result := Current;
- elseif code > 122 then
- Result := Current;
- else
- Result := (code - 32).to_character;
- end;
- end;
-
- to_lower: CHARACTER is
- -- Conversion to the corresponding lower case.
- do
- if code < 65 then
- Result := Current;
- elseif code > 90 then
- Result := Current;
- else
- Result := (code + 32).to_character;
- end;
- end;
-
- is_letter: BOOLEAN is
- do
- inspect
- Current
- when 'A'..'Z','a'..'z' then
- Result := true;
- else
- end;
- ensure
- Result = ('A' <= Current and Current <= 'Z') or
- ('a' <= Current and Current <= 'z');
- end;
-
- is_digit: BOOLEAN is
- -- Belongs to '0'..'9'.
- do
- inspect
- Current
- when '0'..'9' then
- Result := true;
- else
- end;
- ensure
- Result implies ('0' <= Current and Current <= '9');
- end;
-
- is_separator: BOOLEAN is
- -- True when character is a separator.
- do
- inspect
- Current
- when ' ','%T','%N','%R','%U' then
- Result := true;
- else
- end;
- end;
-
- print_on(file: STD_FILE_WRITE) is
- do
- file.put_character('%'');
- file.put_character(Current);
- file.put_character('%'');
- end;
-
- end -- CHARACTER
-